// Buffer
// 1、如何生成 buffer
// 创建大小为 10 的空 buffer
let buf1 = Buffer.alloc(10);
let buf4 = Buffer.allocUnsafe(10);
// 根据内容直接创建 buffer
let buf2 = Buffer.from('hello world');
// 2、buffer 转字符串
// 3、buffer 转 base64
// 4、buffer 合并
const buf = require('buffer');

console.log(buf1);
console.log(buf4);
console.log(Buffer.byteLength(buf1));
console.log(buf1.length);
console.log(buf2);
console.log(Buffer.byteLength(buf2));
console.log(buf2.length);
console.log(buf2.toString('base64'));
console.log(buf2.toString());
buf1.write('you are my good friend');
console.log(buf1.toString());
console.log(buf1.toJSON());

let buf3 = Buffer.concat([buf1,buf2], 30);
console.log(buf1.length);
console.log(buf2.length);
console.log(buf3.length);  //长度叠加
console.log(buf3);
// console.log(buf.consts.MAX_LENGTH);

let buf5 = Buffer.from(buf1);
console.log(buf5);

var arr = new Uint16Array(2);
console.log(arr.buffer);
